<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Boost 搜索引擎</title>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    html,
    body {
        height: 100%;
    }

    /* 类选择器 */
    .container {
        width: 800px;
        margin: 0px auto;
        margin-top: 15px;
    }

    /* 符合选择器 */
    .container .search {
        width: 100%;
        height: 52px;
    }


    .container .search input {
        width: 600px;
        height: 50px;
        border: 1px solid grey;
        border-right: none;
        float: left;
        padding-left: 10px;
        color: #ccc;
        font-size: 15px;
    }

    .container .search button {
        float: left;
        width: 120px;
        height: 50px;
        background-color: #007cff;
        color: #fff;
        font-size: 17px;
        font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    }

    .container .result {
        width: 100%;
    }

    .container .result .item {
        margin-top: 15px;
    }

    .container .result .item a {
        display: block;
        text-decoration: none;
        font-size: 20px;
        color: #4e6ef2;
    }

    .container .result .item a:hover {
        text-decoration: underline;
    }

    .container .result .item p {
        font-size: 15px;
        font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
    }

    .container .result .item i {
        display: block;
        font-style: normal;
        color: green;
        font-family: 'Times New Roman', Times, serif;
    }
</style>

<body>
    <div class="container">
        <div class="search">
            <input type="text" value="输入关键字...">
            <button onclick="Search()">搜索一下</button>
        </div>

        <div class="result">
            <!-- <div class="item">
                <a href="#">这是标题</a>
                <p>这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要</p>
                <i>urlurlurlurlurlurlurlurlurlurlurlurl</i>
            </div>
            <div class="item">
                <a href="#">这是标题</a>
                <p>这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要</p>
                <i>urlurlurlurlurlurlurlurlurlurlurlurl</i>
            </div>
            <div class="item">
                <a href="#">这是标题</a>
                <p>这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要</p>
                <i>urlurlurlurlurlurlurlurlurlurlurlurl</i>
            </div>
            <div class="item">
                <a href="#">这是标题</a>
                <p>这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要</p>
                <i>urlurlurlurlurlurlurlurlurlurlurlurl</i>
            </div>
            <div class="item">
                <a href="#">这是标题</a>
                <p>这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要</p>
                <i>urlurlurlurlurlurlurlurlurlurlurlurl</i>
            </div>
            <div class="item">
                <a href="#">这是标题</a>
                <p>这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要</p>
                <i>urlurlurlurlurlurlurlurlurlurlurlurl</i>
            </div>
            <div class="item">
                <a href="#">这是标题</a>
                <p>这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要</p>
                <i>urlurlurlurlurlurlurlurlurlurlurlurl</i>
            </div> -->

        </div>
    </div>
    <script>
        function Search() {
            let query = $(".container .search input").val();
            console.log("query = " + query); // console 是浏览器终端
            $.ajax({
                type: "GET",
                url: "/s?word=" + query,
                success: function (data) {
                    console.log(data);
                    BuildHtml(data);
                }
            })
        }
        function BuildHtml(data){
            let result_lable = $(".container .result");
            result_lable.empty();

            for(let elem of data){
                // console.log(elem.title);
                // console.log(elem.url);
                let a_lable = $("<a>", {
                    text:elem.title,
                    href:elem.url,
                    // 跳转到新页面
                    target:"_blank"
                });
                let p_lable = $("<p>",{
                    text:elem.desc
                });
                let i_lable = $("<i>",{
                    text:elem.url
                });
                let div_lable = $("<div>",{
                    class:"item"
                });
                a_lable.appendTo(div_lable);
                p_lable.appendTo(div_lable);
                i_lable.appendTo(div_lable);
                div_lable.appendTo(result_lable);
            }
        }

    </script>
</body>

</html>